<script language="javascript" type="text/javascript">
	$(function()
	{
		var now = new Date();
		now.setDate(now.getDate()-5);
		$('.date-pick').datePicker(
			{
				altFormat: "yy-mm-dd",
				startDate: now,
				endDate: ""				
			}			
		);		
	});
	
</script>
<script language="javascript" type="text/javascript" src="/js/script.js"></script>
<?php
//print_r($this->event_arr);
$start_time = $this->event_arr['start_time'];
$stime_arr = explode(":", $start_time);
$stime_session = explode(" ", $start_time);
$s_hr = $stime_arr[0];
$s_min_arr = $stime_arr[1];
$s_min_arr = explode(" ", $s_min_arr);
$s_min = $s_min_arr[0];

$stime_session = $stime_session[1];

$end_time = $this->event_arr['end_time'];
$etime_arr = explode(":", $end_time);
$etime_session = explode(" ", $end_time);
$e_hr = $etime_arr[0];
$e_min_arr = $etime_arr[1];
$e_min_arr = explode(" ", $e_min_arr);
$e_min = $e_min_arr[0];
$etime_session = $etime_session[1];

?>
<div align="center" style="width: 950px;">
<form name="frmEditEvent" method="POST" action="">
	<table border="0" width="95%" cellpadding="1" cellspacing="2" style="line-height: 35px;">
		<tr>
			<td colspan="4" align="left" style="line-height: 25px;"><h4 class="title">Edit Events</h4></td>
		</tr>
		<tr>
			<td align="left">Customer</td>
			<td colspan="3" align="left">
				<select name="cmbCustomer" id="cmbCustomer">
					<option value=""></option>
					<?php
						foreach ($this->cust_arr as $cust_entry) :
					?>
						<option value="<?php echo $cust_entry['customer_id']; ?>" <?php echo ($cust_entry['customer_id'] == $this->event_arr['customer_id'])? "selected":""; ?>><?php echo $cust_entry['customer_name']; ?></option>
					<?php
						endforeach;
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td align="left">Date</td>
			<td align="left" colspan="3"><input name="date1" id="date1" class="date-pick" readonly="readonly" value="<?php echo $this->event_arr['date']; ?>" />
				<input type="hidden" name="txtPreDate1" id="txtPreDate1" value="<?php echo $this->event_arr['date']; ?>" /></td>			
		</tr>
		<tr>
			<td align="left" colspan="2" style="padding: 15px 0 10px 0;"><b><h3>Activities</h3></b></td>			
		</tr>
		<tr>
			<td align="center" valign="top"><?php echo $this->curr_user_fname; ?>&nbsp;<?php echo $this->curr_user_lname; ?></td>
			<td align="left" colspan="3">
				<textarea name="user_activity" id="user_activity" rows="3" cols="65"><?php echo $this->event_arr['ACTIVITY_SUB']; ?></textarea>				
			</td>
		</tr>
		<?php
		if(count($this->sub_user_activity_arr) == 0)
			{
		?>
		<tr>
			<td align="left" colspan="4" style="padding: 15px 0 10px 0;"><h3>Do you want to add more users to this event?&nbsp;<input type="checkbox" name="chkShowEle" id="chkShowEle" value="" onclick="showEle('show_users')" /></h3></td>			
		</tr>
		<?php
			} else {
		?>
		<tr>
			<td align="left" colspan="4" style="padding: 15px 0 10px 0;"><h4 style="color: #000000;"><img src="/images/icons/error-2.gif" />&nbsp;There are another <?php echo count($this->sub_user_activity_arr); ?> user(s) participated for this event. Do you want to view them?<br /><span style="color: #92b22c; font-size: 11px; font-weight: bold;">click on the check box to view members</span> <input type="checkbox" name="chkShowEle" id="chkShowEle" value="" onclick="showEle('show_users')" /></h4></td>			
		</tr>
		<?php
			}
		?>
		<tr id="show_users" style="display: none;">
			<td align="left" valign="top">&nbsp;</td>
			<td align="left" colspan="3">
				<div style="margin: 30px 0 0 0;">
					<table width="100%" border="0" cellpadding="1" cellspacing="2">
					<?php
						$i = 1;
						foreach ($this->user_arr as $key=>$user_entry) :
							if($i == 1)
							{
								echo "<tr>";
							}
							
							$activity = "";
							$add_icon = "";
							$edit_icon = "";
							$delete_icon = "";
							
							foreach ($this->sub_user_activity_arr as $sub_user_activity_entry)
							{
								if($sub_user_activity_entry['user_id'] == $user_entry['userid'])
								{
									$activity .= $sub_user_activity_entry['activity'];
									//$add_icon .= "<img src='/images/icons/a-plus.gif' width='15' height='15' /> Add Activity";
									$add_icon .= "<a href='javascript: void(0);' onclick='addSubTmpUser(\"" .$user_entry['userid'] . "\", \"" . $sub_user_activity_entry['user_id'] . "\", \"edit\", \"" . $this->eventid . "\")'><img src='/images/icons/a-plus.gif' width='15' height='15' /> Add Activity</a>";
									$edit_icon .= "<img src='/images/icons/edit.gif' width='15' height='15' />";
									$delete_icon .= "<img src='/images/icons/a-minus.gif' width='15' height='15' />";
								} else {
									$activity .= "";
									$add_icon .= "<a href='javascript: void(0);' onclick='addSubTmpUser(\"" . $sub_user_activity_entry['user_id'] . "\", \"\", \"add\", \"" . $this->eventid . "\")'><img src='/images/icons/a-plus.gif' width='15' height='15' /> Add Activity</a>";
									$edit_icon .= ""; 								
									$delete_icon .= ""; 								
								}
							}
					?>
						<td style="line-height: 30px;">
							<input type="checkbox" name="chkMultipleUsers[]" id="chkMultipleUsers<?php echo $user_entry['userid']; ?>" value="<?php echo $user_entry['userid']; ?>" onclick="addActivityUsers(<?php echo $user_entry['userid']; ?>, <?php echo count($this->user_arr); ?>);" />&nbsp;<?php echo $user_entry['first_name']; ?>&nbsp;<?php echo $user_entry['last_name']; ?>(<?php echo $user_entry['userlevel']; ?>) &nbsp; <a href="javascript: void(0);" class="hand_cursor" onclick="removeSubUserText(<?php echo $user_entry['userid']; ?>,<?php echo $this->event_arr['event_id']; ?>)"><?php echo $delete_icon; ?></a> &nbsp; <div id="completed" style="display: none;float: left; position: absolute; left: 480px; top: 500px;"></div>
							<div id="div_users<?php echo $user_entry['userid']; ?>" style="display: none;"><textarea name="user_activity[]" id="user_activity_<?php echo $user_entry['userid']; ?>" rows="3" cols="65" onblur="addSubTmpUser('<?php echo $user_entry['userid']; ?>', '<?php echo $user_entry['userid']; ?>', 'add', '<?php echo $this->event_arr['event_id']; ?>')"><?php echo stripslashes($activity); ?></textarea><input type="hidden" name="txtUserId[]" id="txtUserId<?php echo $user_entry['userid']; ?>" value="<?php echo $user_entry['userid']; ?>" /><br /><?php echo $add_icon; ?></div>
										
						</td>						
					<?php						
						endforeach;			
					?>			
					</table>
				</div>
			</td>			
		</tr>
		<tr>
			<td align="left">Time Chargeble</td>
			<td align="left" colspan="3"><input type="radio" name="txtTimeChargeble" id="txtTimeChargeble" value="1" <?php echo ($this->event_arr['time_charge'] == 1)?"checked":""; ?> />Yes&nbsp;<input type="radio" name="txtTimeChargeble" id="txtTimeChargeble" value="0" <?php echo ($this->event_arr['time_charge'] == 0)?"checked":""; ?> />No</td>
		</tr>
		<tr>
			<td align="left">Transport Chargeble</td>
			<td align="left" colspan="3"><input type="radio" name="txtTransportChargeble" id="txtTransportChargeble" value="1" <?php echo ($this->event_arr['transport'] == 1)?"checked":""; ?> />Yes&nbsp;<input type="radio" name="txtTransportChargeble" id="txtTransportChargeble" value="0" <?php echo ($this->event_arr['transport'] == 0)?"checked":""; ?> />No</td>
		</tr>
		<tr>
			<td align="left">Service Agreement</td>
			<td align="left" colspan="3"><input type="radio" name="txtServiceAgreement" id="txtServiceAgreement" value="1" <?php echo ($this->event_arr['service_agreement'] == 1)?"checked":""; ?> />Yes&nbsp;<input type="radio" name="txtServiceAgreement" id="txtServiceAgreement" value="0" <?php echo ($this->event_arr['service_agreement'] == 0)?"checked":""; ?> />No</td>
		</tr>
		<tr>
			<td align="left" valign="top">Additional Text</td>
			<td align="left" colspan="3"><textarea name="additional_text" id="additional_text" rows="3" cols="65"><?php echo $this->event_arr['additional_text']; ?></textarea></td>
		</tr>
		<tr>
			<td align="left">Start Time:</td>
			<td align="left" colspan="3" valign="middle">
				<div id="sample2">
					<!--<input type="text" name="s2Time1" id="s2Time1" class="inp-form" style="width: 70px;" value="" readonly="readonly" />-->
					<select name="cmbSthr" id="cmbSthr" style="width: 70px;">
						<option value="#">Hours</option>
						<?php
							for ($i = 1; $i <= 12; $i++)
							{
								if($i < 10) {
									$i = "0" . $i;
								}
						?>
								<option value="<?php echo $i; ?>" <?php echo($i == $s_hr)?"selected":""; ?>><?php echo $i; ?></option>
						<?php
							}
						?>		
					</select> - 
					<select name="cmbStmin" id="cmbStmin" style="width: 80px;">
						<option value="#">Minutes</option>
						<?php
							for ($i = 0; $i < 60; $i=$i+5 )
							{
								if($i < 10) {
									$i = "0" . $i;
								} else if($i == 0)
								{
									$i = "00";
								}
								
						?>
								<option value="<?php echo $i; ?>" <?php echo($i == $s_min)?"selected":""; ?>><?php echo $i; ?></option>
						<?php
							}
						?>		
					</select> -
					<select name="timeAbbr" id="timeSAbbr" style="width: 50px;">
						<option value="AM" <?php echo($stime_session == "AM")?"selected":""; ?>>AM</option>
						<option value="PM" <?php echo($stime_session == "PM")?"selected":""; ?>>PM</option>
					</select>
				</div>
			</td>
		</tr>
		<tr>
			<td align="left">End Time:</td>
			<td align="left" colspan="3" valign="middle">
				<div id="sample2">
					<!--<input type="text" name="s2Time2" id="s2Time2" class="inp-form" style="width: 70px;" value="" readonly="readonly" />-->
					<select name="cmbEndhr" id="cmbEndhr" style="width: 70px;">
						<option value="#">Hours</option>
						<?php
							for ($i = 1; $i <= 12; $i++)
							{
								if($i < 10) {
									$i = "0" . $i;
								}
						?>
								<option value="<?php echo $i; ?>" <?php echo($i==$e_hr)?"selected":""; ?>><?php echo $i; ?></option>
						<?php
							}
						?>		
					</select> - 
					<select name="cmbEndmin" id="cmbEndmin" style="width: 80px;">
						<option value="#">Minutes</option>
						<?php
							for ($i = 0; $i < 60; $i=$i+5 )
							{
								if($i < 10) {
									$i = "0" . $i;
								} else if($i == 0)
								{
									$i = "00";
								}
								
						?>
								<option value="<?php echo $i; ?>" <?php echo($i==$e_min)?"selected":""; ?>><?php echo $i; ?></option>
						<?php
							}
						?>		
					</select> -
					<select name="timeAbbr" id="timeEAbbr" style="width: 50px;">
						<option value="AM" <?php echo($etime_session == "AM")?"selected":""; ?>>AM</option>
						<option value="PM" <?php echo($etime_session == "PM")?"selected":""; ?>>PM</option>
					</select>									
				</div>
			</td>
		</tr>
		<tr>
			<td align="left">Event Type</td>
			<td align="left" colspan="3">
				<select name="eventtype" id="eventtype">
					<option value="">Select Event</option>
					<option value="visit" <?php echo($this->event_arr['event_type'] == "visit")?"selected":""; ?>>Customer Visit</option>
					<option value="call" <?php echo($this->event_arr['event_type'] == "call")?"selected":""; ?>>On Call</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="left" colspan="4">
				<div style="padding: 30px 0 0 0;" class="edit-icoset">
					<a id="updateevent" title="" href="javascript: void(0);" onclick="updateEvent('<?php echo $this->userlevel; ?>')"><img alt="" src="/images/icons/save-2.gif">Update Event</a>
					<input type="hidden" name="txtEventId" id="txtEventId" value="<?php echo $this->event_arr['event_id']; ?>" />
				</div>	
			</td>
					
		</tr>
	</table>
</form>
</div>